//
// Created by wsl on 1/6/23.
//

#ifndef DEFECT_DEPTH_DEFECT_DEPTH_H
#define DEFECT_DEPTH_DEFECT_DEPTH_H
#include <map>
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "clipper.h"
#include "Eigen/Eigen"
#include <Eigen/Core>
#include <Eigen/Dense>
#include <Eigen/Geometry>
#include "circle_detect.h"

Eigen::Vector4d PlaneFitting(const std::vector<Eigen::Vector3d>& plane_pts);

cv::Mat warpImage(cv::Mat src,const cv::Mat& M,cv::Mat dst);
std::vector<cv::Point> warpPoly( std::vector<cv::Point> poly,const cv::Mat& M);
cv::Mat modifyMatrix(std::vector<cv::Point> dst_circles,const std::vector<cv::Point>&  src_circles,int src_camera,cv::Mat M);
class DefectDepth{
public:
    std::vector<double> get_rot_diff_depth(cv::Mat depth, std::vector<cv::Point> poly1,std::vector<cv::Point> poly2);
    std::vector<double> get_polys_depth(cv::Mat depth,const cv::Mat& gray, std::vector<std::vector<cv::Point>> poly);
    std::vector<double> get_depth_basemask(cv::Mat depth,cv::Mat mask, const std::vector<std::vector<cv::Point>>& poly,const cv::Mat& M);
    std::vector<double> get_depth_minmax(cv::Mat depth, std::vector<std::vector<cv::Point>> poly,const cv::Mat& M);
    std::vector<cv::Point> shrink_poly(std::vector<cv::Point>poly,float ratio);
    double get_plane_diff_depth(cv::Mat depth, std::vector<cv::Point> poly1,std::vector<cv::Point> poly2);
    double test_line_plane_depth(cv::Mat depth,cv::Mat& gray, std::vector<cv::Point> poly,Circle c0);
    std::vector<double> get_line_plane_depth(cv::Mat depth,cv::Mat& gray, std::vector<std::vector<cv::Point>> poly,
                                             Circle c0,const cv::Mat& M);
    std::vector<double> get_line_planev2_depth(cv::Mat depth,cv::Mat& gray, std::vector<std::vector<cv::Point>> poly,
                                             Circle c0,const cv::Mat& M);
    double get_hangao(cv::Mat depth,cv::Mat& gray,cv::Point c0);

    std::vector<double> get_plane_depth(cv::Mat depth,cv::Mat& gray, std::vector<std::vector<cv::Point>> poly,
                                             Circle c0,int r0,int r1,const cv::Mat& M);


public:
    float expand_ratio=1.2;
    float shrink_ratio=1.0;
    double alpha=1.6;
    double edage_r=600;
    double mid_r=375;
    double small_r=270;
    int items=5;
    bool viz= false;
    bool mean_flag=true;

};
#endif //DEFECT_DEPTH_DEFECT_DEPTH_H
